package com.horoscope.astrology.zodiac.signs.free

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import android.util.Log
import com.facebook.FacebookSdk
import com.flurry.android.FlurryAgent
import com.google.android.gms.ads.MobileAds
import com.tencent.mmkv.MMKV

/**
 *  作者    1024
 *  时间    2020/3/17 下午2:39
 *  文件    constellation-android
 *  描述    优化SDK初始化
 */
open class SDKInitProvider : ContentProvider() {

    override fun insert(uri: Uri, values: ContentValues?): Uri? {
        return null
    }

    override fun query(
        uri: Uri,
        projection: Array<String>?,
        selection: String?,
        selectionArgs: Array<String>?,
        sortOrder: String?
    ): Cursor? {
        return null
    }

    override fun onCreate(): Boolean {
        initFaceBook()
        initAdMob()
        initFlurry()
        initMMKV()
//        initAppFlyer()
        return true
    }

    private fun initAdMob() {
        MobileAds.initialize(this.context!!) {}
    }

    private fun initFlurry() {
        FlurryAgent.Builder()
            .withLogEnabled(true)
            .withCaptureUncaughtExceptions(true)
            .withContinueSessionMillis(10000)
            .withLogLevel(Log.VERBOSE)
            .build(this.context!!, this.context!!.getString(R.string.ID_Flurry))
    }

    private fun initFaceBook() {
        // 文档是说自动调用，但是不初始化还会有问题
        FacebookSdk.sdkInitialize(this.context!!)
    }

    // FaceBook ad 初始化
//    private fun initAudienceNetworkAd() {
//        AudienceNetworkInitializeHelper.initialize(this.context!!)
//    }

    /**
     * MMKV初始化 及 sp数据迁移
     */
    private fun initMMKV() {
        MMKV.initialize(this.context!!)
//        if (AppSettingManager.readInt("mmkv", 0) != 1) {
//            AppSettingManager.saveInt(1, "mmkv")
//            val old = getSharedPreferences("config", MODE_PRIVATE)
//            AppSettingManager.mmkv.importFromSharedPreferences(old)
//            val sss = AppSettingManager.mmkv.allKeys()
//            for (i in sss) {
//                Logger.debug(TAG, "" + i)
//            }
//        }
    }

    // 公司自己的SDK
    private fun initAppFlyer() {
//        TaskManager.getInstance((this.context as Application)).init()
    }

    override fun update(
        uri: Uri,
        values: ContentValues?,
        selection: String?,
        selectionArgs: Array<String>?
    ): Int {
        return 0
    }

    override fun delete(uri: Uri, selection: String?, selectionArgs: Array<String>?): Int {
        return 0
    }

    override fun getType(uri: Uri): String? {
        return null
    }

}